![]() |
Introduction to Resources |
|
|
|
|
|
|
Cursors |
|
Introduction |
|
A cursor is an object used to show or represent the current position of the mouse on the screen. Microsoft Windows ships with many cursors as follows: |
| IDC_APPSTARTING | IDC_ARROW | IDC_CROSS | IDC_HAND | ||||
| IDC_HELP | IDC_IBEAM | IDC_ICON | Not Used(*) | IDC_NO | |||
| IDC_SIZE | Not Used(*) | IDC_SIZEALL | IDC_SIZENESW | IDC_SIZENS | |||
| IDC_SIZENWSE | IDC_SIZEWE | IDC_UPARROW | IDC_WAIT |
|
(*) The IDC_ICON and the IDC_SIZE cursors should not be used anymore. To use a cursor, the user points the mouse on a specific item. Because a cursor can be large and because many areas of a window can act upon receiving the mouse, the cursor has a special area called a hot spot so that, no matter how big the cursor is, the mouse can apply its behavior only on what the hot spot touches. For an arrow cursor, which is the most widely used cursor, the hot spot is located on the tip of the arrow pointing to the top-left corner. When you create your own cursor, you can position the hot spot anywhere on the cursor as you wish but you must always know where the hot spot of your cursor is and you should always make it obvious to the user. |
|
Cursor Creation |
|
To use any of the above cursors, simply pass its name as the second argument to the LoadCursor() function. Here is an example: LoadCursor(NULL, IDC_HELP); Creating your own cursor or a few cursors for your application involves a few steps. These steps can be different depending on the programming environment you are using; but the process is the same. You should first create a cursor. You can copy one of the existing cursors that ship with your programming environment. Both Borland C++ Builder and Microsoft Visual C++ install many cursors. You can still create your own cursor from scratch. For Borland C++ Builder, this can be done using the Image Editor, which is a separate application that ships with the compiler. For Microsoft Visual C++, you can do this using the built-in image editor. The cursor is its own file with the extension .cur. After creating and possibly testing the cursor, you must create a header file, usually called Resource.h, in which you define the cursor. In this file, each cursor must be defined with the formula: #define Identifier Constant The #define preprocessor is required. The identifier must be a non-quoted string that will serve to identify the cursor. The Constant must an integer with a unique value in the file. After creating the header file, you must create the main resource file. This file has an extension of .rc and it usually has the same name as the project but this is only a habit. In the resource file, you should first include the header file you just created. In the file, each resource must be represented. For a cursor, you use the formula: Identifier CURSOR FileName The Identifier must be the same you defined in the Resource header file. The keyword CURSOR must be used to let the compiler know that this particular resource is a cursor, making it distinct from other resources such as icons or bitmaps, etc. The FileName must be the cursor with extension .cur that you had created already. To use the resource (.rc) file in your project, you must explicitly Add it to your project. Neither Borland C++ Builder nor Microsoft Visual C++ will add this rc file for you. The main difference is that, with Borland C++ Builder, you can add this rc file before or after compiling it, as long as the compile is aware of it before building the whole project. With Microsoft Visual C++, you should first (although you don't have to) add the rc file to your project. In fact, this makes it easy for Microsoft Visual C++ to compile the rc file for you. |
|
Using Borland C++ Builder |
|
|
|
|
|
Custom Cursors |
|
After creating the resource file, you must compile it. After the rc file has been compiled, it creates a file with extension .res. In Borland C++ Builder, you must explicitly compile the resource file, which is easy but you must remember to do it. Microsoft Visual C++ transparently compiles the rc file for you but you must have added it to your project. After creating the resource file, because the Resource header file holds the identifiers of the resource, remember to include it in the file where you want to use the resources. This is done with a simple: #include "Resource.h" To use your own cursor, assign the result of the LoadCursor() function to the hCursor member variable of the WNDCLASS or the WNDCLASSEX class. The first argument of the function should be the instance of the application you are using. For the second argument, use the MAKEINTRESOURCE macro, passing it the identifier of the cursor. |
|
|
|
|
Icons |
|
Introduction |
|
An Icon is a small picture that displays in various places to represent an application. For example, an icon displays on the top-left section of the title and is defined by the application. In this case it also holds the system menu. An icon is also used in Windows Explorer and My Computer to represent an application. Icons are also used by other controls (tree views, list views, combo boxes, etc). The Win32 library ships with only a few icons. Microsoft Windows, on the other hand, ships with various icons for its internal use. The icon we have used so far is a standard icon provided in case you don't have one on your own. This means that you are free to create a custom icon for your application. |
|
Icon Creation |
|
To provide your own icon for your application, you should create one or two icons (you can even create more) for your application. Both icons have the same name and, in fact, are stored as one file. Internally, the operating system will choose which one to display and when, depending on the scenario. An icon is created following the same steps as we described for a cursor, with a few differences. While a cursor is mostly limited to two colors, an icon can use up to 16 colors. |
|
|
|
|
|
||
| Previous | Copyright © 2003-2005 FunctionX, Inc. | Next |
|
|
||